use crate::components::enums::{
    HttpMethod,HttpRequestContentType,HttpResponseContentType,
    AppMode,ProtocolType,ConnectionStatus,NetworkCommand,
    NetworkEvent
};
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::task::JoinHandle;

// App 核心组件。它需要串联各个ui间的数据，和键盘、鼠标事件
pub struct App {
    // 网络通信相关状态
    pub connection_status: ConnectionStatus,
    pub cmd_tx: Option<UnboundedSender<NetworkCommand>>,
    pub event_tx: Option<UnboundedSender<NetworkEvent>>,
    pub event_rx: Option<UnboundedReceiver<NetworkEvent>>,
    pub task_handle: Option<JoinHandle<()>>,
    // 通用部分
    pub protocol: ProtocolType, // "TCP", "UDP / HTTP"
    pub server_addr: String,    // "127.0.0.1:8080" default
    pub logs: String,           // 日志信息
    pub scroll_position: usize, // 滚动位置
    pub mode: AppMode,          // 当前的输入模式
    pub current_input: String,  // 当前编辑框的文本缓冲区

    // tcp / udp 部分
    pub request_data: String,  // 要发送的数据 for tcp/udp
    pub received_data: String, // 接收到的数据(格式化后的) for tcp/udp

    // http 部分
    pub request_http_headers: Vec<(String, String)>,
    pub request_http_params: Vec<(String, String)>,
    pub request_http_body: String,
    pub http_method: HttpMethod,
    pub request_content_type: HttpRequestContentType,
    pub response_http_status_code: u16,
    pub response_http_body: String,
    pub response_http_headers: Vec<(String, String)>,
    pub response_http_cookies: Vec<String>,
    pub response_content_type: HttpResponseContentType,

    // 退出程序标志
    pub quit_tag: bool,
}



// 鼠标滚动事件
pub trait ScrollTrait {
    fn scroll_down(&mut self) -> bool;

    fn scroll_up(&mut self) -> bool;
}